package lcr;

public class Test0172 {
}

class Solution0172_1 {
    int[] scores;
    public int countTarget(int[] scores, int target) {
        if (scores.length==0)return 0;

        this.scores=scores;
        int left= binarySearch(target,true);
        int right=binarySearch(target,false);

        return right-left;
    }

    public int binarySearch(int target,boolean flag){
        int right = scores.length,left=0;
        while (left<=right&&right>=0&&left<scores.length){
            int mid = (left + right) >> 1;

            if (scores[mid]>target||(flag&&scores[mid]==target)){
                right=mid-1;
            }else {
                left=mid+1;
            }
        }

        return left;
    }
}
